package com.dhcc.bpm.modules.system.wrapper;

import com.dhcc.bpm.common.cache.DictCache;
import com.dhcc.bpm.common.cache.SysCache;
import com.dhcc.bpm.modules.system.entity.User;
import com.dhcc.bpm.modules.system.vo.UserVO;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;

import java.util.List;

/**
 * @ClassName UserWrapper
 * @Description 包装类,返回视图层所需的字段
 * @Author sjm
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
public class UserWrapper extends BaseEntityWrapper<User, UserVO> {

	public static UserWrapper build() {
		return new UserWrapper();
	}

	@Override
	public UserVO entityVO(User user) {
		UserVO userVO = BeanUtil.copy(user, UserVO.class);
		assert userVO != null;
		List<String> roleName = SysCache.getRoleNames(user.getRoleId());
		List<String> deptName = SysCache.getDeptNames(user.getDeptId());
		userVO.setPassword(null);
		userVO.setRoleName(Func.join(roleName));
		userVO.setDeptName(Func.join(deptName));
		userVO.setSexName(DictCache.getValue("sex", String.valueOf(Func.toInt(user.getSex()))));
		return userVO;
	}

}
